import os,cv2
from matplotlib import pyplot as plt
import matplotlib.image as mpimg

rownum = 2
colnum = 4

test_dir = 'D:/Data/Research_data/dataset/FER/RAFDB/basic/Image/rafdb/test/1/'
# ['Anger', 'Disgust', 'Fear', 'Happiness', 'Neutral', 'Sadness', 'Surprise']
# label_exp = {'1': 'Surprise', '2': 'Fear', '3': 'Disgust', '4': 'Happiness', '5': 'Sadness', '6': 'Anger', '7': 'Neutral'} 

# img_paths = []

# for i in range(1,8):
#     imgs_dir = test_dir + str(i) + '/'
#     img_name = os.listdir(imgs_dir)[20]  # 20表示取序列中的某一张图像
#     img_path = imgs_dir + img_name
#     img_paths.append(img_path)
#     # print(img_path)


img_name = os.listdir(test_dir)[20]  # 20表示取序列中的某一张图像
filename = test_dir + img_name
scale = [1, 1/2, 1/4, 1/6, 1/8, 1/12, 1/14, 1/16]
image2display = cv2.imread(filename)
for item in range(8):
    position = item + 1
    image = mpimg.imread(filename)
    img_shape = image.shape
    new_w,new_h = int(img_shape[0]*scale[item]),int(img_shape[1]*scale[item])
    image2display = cv2.resize(image2display,(new_w,new_h))
    # image2display = cv2.cvtColor(image2display,cv2.COLOR_RGB2BGR)
    cv2.imwrite("{}.png".format(new_w),image2display)
    # cv2.imshow('x1{}'.format(item),image2display)
    # cv2.waitKey()
    # print(image2display.shape)
    if item > 2:
        position = item + 1
        item = item % 7
    plt.subplot(rownum,colnum,position)
    plt.imshow(image2display)
    plt.axis('off')
    print(filename, item)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = -0.1, wspace = 0.2)
# plt.margins(0,0)
plt.savefig('./mul_scale.png', dpi=300, bbox_inches='tight')  # 保存图片
plt.show()
